import { MenuState } from "@/redux/interface";
import * as types from '@/redux/mutation-types';
import { Draft, produce } from "immer";
import { Action } from "redux";

const menuState: MenuState = {
    isCollapse: false,
    menuList: []
}
interface SET_MENU_LIST extends Action {
    type: typeof types.SET_MENU_LIST,
    menuList: Menu.MenuOptions[]
}
interface UPDATE_COLLAPSE extends Action {
    type: typeof types.UPDATE_COLLAPSE,
    isCollapse: boolean
}
// menu reducer
type ActionType = SET_MENU_LIST | UPDATE_COLLAPSE;
const menu = (state: MenuState = menuState, action: ActionType) => {
    return produce(state, (draftState: Draft<MenuState>) => {
        switch (action.type) {
            case types.SET_MENU_LIST:
                draftState.menuList = action.menuList;
                break;
            case types.UPDATE_COLLAPSE:
                draftState.isCollapse = action.isCollapse;
                break;
            default:
                break;
        }
    })
}

export default menu;